/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.client.java;

import net.interknit.knitter.client.SourceWriter;
import net.interknit.knitter.client.SourceWriterFactory;
import net.interknit.knitter.client.layout.ArrayEl;
import net.interknit.knitter.client.layout.CollectionEl;
import net.interknit.knitter.client.layout.EndpointEl;
import net.interknit.knitter.client.layout.MapEl;
import net.interknit.knitter.client.layout.MethodEl;
import net.interknit.knitter.client.layout.TypeEl;

/**
 *
 */
public class JavaSourceWriterFactory implements SourceWriterFactory
{
	@Override
	public SourceWriter create(TypeEl typeElement)
	{
		SourceWriter writer = null;

		if(typeElement instanceof ArrayEl)
			writer = new JavaArraySourceWriter();
		else if(typeElement instanceof CollectionEl)
			writer = new JavaCollectionSourceWriter();
		else if(typeElement instanceof MapEl)
			writer = new JavaMapSourceWriter();
		else if(typeElement instanceof EndpointEl)
			writer = new JavaEndpointSourceWriter();
		else if(typeElement instanceof MethodEl)
			writer = new JavaMethodSourceWriter();
		else if(typeElement instanceof TypeEl)
			writer = new JavaTypeSourceWriter();
		else
			throw new RuntimeException("typeElement must be a valid subclass of TypeEl: " + typeElement);

		writer.setTypeEl(typeElement);

		return writer;
	}
}
